package Day01.ReflectDemo.DoMain;

//写一个框架 可以读取文件执行
//  框架类

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@Pro(className = "Day01.ReflectDemo.DoMain.Demo1", methodName = "show")

public class Practise {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
//        Properties pro = new Properties();
//        ClassLoader classLoader = Practise.class.getClassLoader();
//        InputStream is = classLoader.getResourceAsStream("Day01/pro.properties");
//        pro.load(is);
//
//
//        String className = pro.getProperty("className");
//        String methodName = pro.getProperty("methodName");
//
//        Class<?> cls = Class.forName(className);
//        Object obj = cls.newInstance();
//
//        Method method = cls.getMethod(methodName);
//
//        method.invoke(obj);

//        1 解析注解
        Class<Practise> practiseClass = Practise.class;
        Pro an = practiseClass.getAnnotation(Pro.class);
        String className = an.className();
        String methodName = an.methodName();

        Class<?> cls = Class.forName(className);
        Object obj = cls.newInstance();

        Method method = cls.getMethod(methodName);

        method.invoke(obj);
    }
}
